package eu.news.template;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import eu.news.config.SystemConfig;

/**
 * @author wzz
 * 
 */
public class WebPage {
	//Map<String, Object> parameters = new HashMap<String, Object>();
	String template = null;
	String templateName = null;
	String pageName = null;
	HttpServletRequest request = null;
	HttpServletResponse response = null;

	public WebPage(HttpServletRequest request, HttpServletResponse response, 
			String templateName, String pageName) {
		this.request = request;
		this.response = response;
		this.templateName = templateName;
		if (templateName == null)
			this.templateName = SystemConfig.getDefaultTheme();
		this.pageName = pageName;
	}

	public void setParameter(String name, Object value) {
		//parameters.put(name, value);
		request.setAttribute(name, value);
	}

	public void removeParameter(String name) {
		//return parameters.remove(name);
		request.removeAttribute(name);
	}

	/**
	 * 将控制权交给页面，调用此方法之后不应该对response执行操作，其结果将是不可预料的。
	 * 这个方法的正确结果应该是将页面发送到客户端。
	 * @throws IOException 
	 */
	public void forward() throws IOException {
		//当前使用JSP作为模板页
		try {
			request.getRequestDispatcher("/template/"+templateName+"/"+pageName+".jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
	
}
